<?php


namespace App\Models\Admin;


class CustomerMsg extends Base
{
    protected $table = 'customer_msg';
    protected $guarded = [];
    protected $dateFormat = 'U';

    public function cust()
    {
        return $this->belongsTo(CustomerServiceAgent::class,'cust_id','id');
    }

    public function user()
    {
        return $this->belongsTo(User::class,'user_id','id');
    }

    public static function getCount($where)
    {
        $count=self::getWhere($where)->count();
        return $count;
    }

    public static function getList($where,$skip,$size)
    {
        $list=self::getwhere($where)
            ->with([
                'user'=>function($query){
                    $query->with([
                        'setting:id,site_logo',
                    ])->select('id','name','company_id');
                },
                'cust:id,nickname,head_pic'
            ])
            ->orderBy('created_at','desc')
            ->skip($skip)->take($size)
            ->get();
        return $list;
    }

    public static function getWhere($where)
    {
        $select=self::where([]);
        if(!empty($where['user_id']))
            $select=$select->where('user_id',$where['user_id']);
        return $select;
    }


}
